package net.xdclass.plusstudy.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import net.xdclass.plusstudy.entity.User;
import net.xdclass.plusstudy.service.UserService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * UserController
 *
 * @author fxbin
 * @version v1.0
 * @since 2019/2/10 1:30
 */
@RestController
public class UserController {

	@Resource
	private UserService userService;

	/**
	 * 查询全部
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping("/listAll")
	public Object listAll(@RequestParam(value = "page",defaultValue = "1")int page,
						  @RequestParam(value = "size",defaultValue = "10")int size){
		return userService.listAll(page, size);
	}

	/**
	 * 分页级联查询
	 * @param index
	 * @param size
	 * @return
	 */
	@RequestMapping("/listPageForAll")
	public Object listPageForAll(@RequestParam(value = "index",defaultValue = "2")int index,
						  @RequestParam(value = "size",defaultValue = "2")int size){
		Page<User> page = new Page<>(index, size);
		page.setTotal(0);
		Page page1 = userService.selectUserListPage(page);
		return page;
	}

	/**
	 * 根据用户Id查询房子
	 * @param userId
	 * @return
	 */
	@RequestMapping("/getHouseByUser")
	public Object listAll(@RequestParam(value = "userId") int userId){
		return userService.getHouseByUser(userId);
	}

	/**
	 * 添加数据
	 * @param user
	 * @return
	 */
	@RequestMapping("/insert")
	public int insert (User user){
		return userService.insert(user);
	}

	/**
	 * 删除
	 * @param userId
	 * @return
	 */
	@RequestMapping("/remove")
	public int remove(Integer userId){
		return userService.remove(userId);
	}

	/**
	 * 修改
	 * @param user
	 * @return
	 */
	@RequestMapping("/update")
	public int update(User user){
		return userService.update(user);
	}

}

